package com.bill.app.serveur;

import java.io.*;
import java.net.Socket;
import java.util.Hashtable;
import java.util.StringTokenizer;

class NThreadChatSERV extends Thread
{

    NThreadChatSERV(Socket socket, Hashtable LesConnecter, Hashtable tableChat, String text)
    {
        this.tableChat = null;
        this.socket = null;
        lecture = null;
        ecriture = null;
        key = null;
        this.LesConnecter = null;
        this.tableChat = tableChat;
        this.socket = socket;
        StringTokenizer tt = new StringTokenizer(text, "=");
        tt.nextToken();
        key = tt.nextToken().trim();
        this.LesConnecter = LesConnecter;
        try
        {
            ecriture = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
            lecture = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            tableChat.put(key, ecriture);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
        start();
    }

    public void run()
    {
        new Traitement(LesConnecter, tableChat, lecture);
        Thread.yield();
    }

    Hashtable tableChat;
    Socket socket;
    BufferedReader lecture;
    PrintWriter ecriture;
    String key;
    Hashtable LesConnecter;
}
